package com.subaiqiao.yunshiyuan.basis.utils;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * 加密解密
 */
public class Encryption {
    /**
     * MD5加密方法
     * @explain java实现
     * @param str 待加密字符串
     * @return 16进制加密字符串
     */
    public static String encrypt2ToMD5(String str) throws NoSuchAlgorithmException {
        // 加密后的16进制字符串
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        byte[] md5Bytes = md5.digest(str.getBytes(StandardCharsets.UTF_8));
        String md5Str = "";
        for (int i = 0; i < md5Bytes.length; i++) {
            md5Str += Integer.toHexString(md5Bytes[i] | 0xFFFFFF00).substring(6);
        }
        System.out.println(md5Str);
        return md5Str;
    }

}
